#ifndef HTMLPARSER_H_
#define HTMLPARSER_H_

#include <string>
#include "Substituter.h"
#include "./dicionario/Timer.h"
#include <fstream>

using namespace std;

class HTMLParser {
public:
	void removeScripts (std::string &);
	HTMLParser() {
		TOLOWER = 0;
		MAYINDEX = 0;
		ISOLATEBODY = 0;
		REMOVEHEAD = 0;
		REMOVEINLINETAGS = 0;
		REMOVESCRIPTS = 0;
		REMOVESTYLES = 0;
		REMOVEALLTAGS = 0;
		CONVERTHTMLSTRING = 0;
		REMOVEENTERS = 0;
	}
	std::string extractText(std::string);
	
	
	
	void coutStatistics(std::string fileName) {
		ofstream estatistica (fileName.c_str());
		double total = TOLOWER + MAYINDEX + ISOLATEBODY + REMOVEHEAD + REMOVEINLINETAGS + REMOVESCRIPTS + REMOVESTYLES +
		             REMOVEALLTAGS + CONVERTHTMLSTRING + REMOVEENTERS;
		estatistica << "      FUNCAO	      |  TEMPO EXECUCAO" << std::endl;
		estatistica << "toLower:			  |		" << TOLOWER << " " << 100*TOLOWER/total << "%" << std::endl;
		estatistica << "mayIndex:			  |		" << MAYINDEX << " " << 100*MAYINDEX/total << "%" << std::endl;
		estatistica << "isolateBody:		  |		" << ISOLATEBODY << " " << 100*ISOLATEBODY/total << "%" << std::endl;
		estatistica << "removeHead:		  	  |		" << REMOVEHEAD << " " << 100*REMOVEHEAD/total << "%" << std::endl;
		estatistica << "removeInlineTags:	  |		" << REMOVEINLINETAGS << " " << 100*REMOVEINLINETAGS/total << "%" << std::endl;
		estatistica << "removeScripts:	  	  |		" << REMOVESCRIPTS << " " << 100*REMOVESCRIPTS/total << "%" << std::endl;
		estatistica << "removeStyles:		  |		" << REMOVESTYLES << " " << 100*REMOVESTYLES/total << "%" << std::endl;
		estatistica << "removeAllTags:	  	  |		" << REMOVEALLTAGS << " " << 100*REMOVEALLTAGS/total << "%" << std::endl;
		estatistica << "convertHtmlStrings:   |		" << CONVERTHTMLSTRING << " " << 100*CONVERTHTMLSTRING/total << "%" << std::endl;
		estatistica << "removeEnters:		  |		" << REMOVEENTERS << " " << 100*REMOVEENTERS/total << "%" << std::endl;
	}
	
private:
	Substituter substituter;
	void trim(std::string &str);
	bool checkIgnoreCase(std::string str, std::string compared);
	bool mayIndex (const std::string &);
	bool removeHead(std::string &);
	bool isolateBody (std::string &);
	void removeInlineTags (std::string &);
	void removeStyles (std::string &);
	void removeAllTags (std::string &);
	void removeEnters (std::string &);
	void toLower (std::string &);
	
	double TOLOWER;
	double MAYINDEX;
	double ISOLATEBODY;
	double REMOVEHEAD;
	double REMOVEINLINETAGS;
	double REMOVESCRIPTS;
	double REMOVESTYLES;
	double REMOVEALLTAGS;
	double CONVERTHTMLSTRING;
	double REMOVEENTERS;
	Timer  timer;
	
	
	
	\
	/*toLower(htmlPage);
	if (mayIndex(htmlPage)) {
//		cout << endl <<  "745eyhbrtfdthAAAAAAAAAA****************" << endl;
		if (!isolateBody(htmlPage))
			removeHead(htmlPage);
		removeInlineTags(htmlPage);
		removeScripts(htmlPage);
		removeStyles(htmlPage);
//		cout << endl << endl << endl << endl <<"htmlPage: " << htmlPage << endl;
		removeAllTags(htmlPage);
		htmlPage = substituter.convertHtmlString(htmlPage);
		removeEnters(htmlPage);*/
};

#endif /*HTMLPARSER_H_*/
